﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

using RexToy.Collections;
using RexToy.Numeric;

namespace RexToy.UI.WinForm.Pmlx
{
    public class ControlMetaData
    {
        public ControlMetaData(Control control)
        {
            control.ThrowIfNullArgument("control");

            _control = control;
            _delayComputeAttribute = new Dictionary<string, string>();
        }

        private Control _control;
        public Control Control
        {
            get { return _control; }
        }

        private Dictionary<string, string> _delayComputeAttribute;
        public ReadOnlyDictionary<string, string> DelayComputeAttribute
        {
            get { return _delayComputeAttribute; }
        }

        public void AddDelayCompute(string key, string expression)
        {
            _delayComputeAttribute[key] = expression;
        }

        private ControlBehavior _behavior;
        public ControlBehavior Behavior
        {
            get { return _behavior; }
        }

        private Percentage? _height;
        public Percentage? Height
        {
            get
            {
                return _height;
            }
            set
            {
                if (value != null)
                    _behavior |= ControlBehavior.Height;
                else
                    _behavior &= ~ControlBehavior.Height;

                _height = value;
            }
        }

        private Percentage? _width;
        public Percentage? Width
        {
            get
            {
                return _width;
            }
            set
            {
                if (value != null)
                    _behavior |= ControlBehavior.Width;
                else
                    _behavior &= ~ControlBehavior.Width;

                _width = value;
            }
        }

        public bool HeightResizable
        {
            get { return (this._behavior & ControlBehavior.Height) != 0; }
        }

        public bool WidthResizable
        {
            get { return (this._behavior & ControlBehavior.Width) != 0; }
        }

        public bool ControlResizable
        {
            get { return HeightResizable || WidthResizable; }
        }

        public bool DelayCompute
        {
            get { return _delayComputeAttribute.Count > 0; }
        }
    }
}
